<?php

	include_once $_SERVER["DOCUMENT_ROOT"].'/service/entite/uc/UcService.php';
	include_once $_SERVER["DOCUMENT_ROOT"].'/service/entite/role/RoleService.php';
	include_once $_SERVER["DOCUMENT_ROOT"].'/service/entite/uc/UcEntite.php';
	include_once $_SERVER["DOCUMENT_ROOT"].'/service/uc/gereruc/GererUcUcVO.php';
	include_once $_SERVER["DOCUMENT_ROOT"].'/service/uc/gereruc/GererUcVOAssembler.php';
	class GererUcService {
		public static function ajouterUc() {
			$uc = UcService::createUc();
			return GererUcVOAssembler::createGererUcUcVO($uc);
		}
		
		public static function modifierUc($id) {
			$uc = UcService::getUcForModification($id);
			return GererUcVOAssembler::createGererUcUcVO($uc);
		}
		
		public static function validerUc(GererUcUcVO $gererUcUcVO) {
			$uc = GererUcVOAssembler::getEntity($gererUcUcVO);
			//Sauvegarde de l'activité
			UcService::save($uc);
			
			//sauvegarde de la liste des rôles
			$listeIdRole = Array();
			foreach ($gererUcUcVO->listeRoleVO as $gererUcRoleVO) {
				$listeIdRole[] = $gererUcRoleVO->id;
			}
			UcService::saveListeIdRole($uc, $listeIdRole);
		}
		
		public static function supprimerUc($id) {
			UcService::supprimerUc($id);
		}
		
		public static function getListeUc() {
			$listeUc = UcService::getListeUc();
			return GererUcVOAssembler::createListeGererUcUcVO($listeUc);
		}
		
		public static function getGererUcRoleVOByID($idRole) {
			$gererUcRoleVO = RoleService::getRoleForModification($idRole);
			return GererUcVOAssembler::createGererUcRoleVO($gererUcRoleVO);
		}
		public static function convertListeIdToListeRoleVO($listeIdGererUcRoleVO) {
			$listeGererUcRoleVO = Array();
			foreach ($listeIdGererUcRoleVO as $idGererUcRoleVO ) {
				$listeGererUcRoleVO[] = GererUcVOAssembler::createGererUcRoleVOMinimaliste($idGererUcRoleVO);
			}
			return $listeGererUcRoleVO;
		}
		
	}
?>